# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgbase=caido
pkgname=('caido-cli' 'caido-desktop')
pkgver=0.53.1
pkgrel=1
pkgdesc='Intercepting proxy to replay, inject, scan and fuzz HTTP requests.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-webapp' 'blackarch-proxy' 'blackarch-scanner'
        'blackarch-fuzzer')
url='https://caido.io/'
license=('custom:private')
options=(!strip)
_appimage="caido-desktop-v$pkgver-linux-$CARCH.AppImage"
noextract=($_appimage)
source=('LICENSE')
source_x86_64=(
  "https://caido.download/releases/v$pkgver/caido-desktop-v$pkgver-linux-x86_64.AppImage"
  "https://caido.download/releases/v$pkgver/caido-cli-v$pkgver-linux-x86_64.tar.gz"
)
source_aarch64=(
  "https://caido.download/releases/v$pkgver/caido-desktop-v$pkgver-linux-aarch64.AppImage"
  "https://caido.download/releases/v$pkgver/caido-cli-v$pkgver-linux-aarch64.tar.gz"
)
sha512sums=('83a63c23f42f381a1f312387896598409dbd7b6dad8c9d89b7b747ff09f143c173272c724f0f6755ddd0bb26662866a8f7a8992a521f659be57ef0fb82f0d917')
sha512sums_x86_64=('e3a5433c590c0fc7af601b8f58e0986ad6af7dd3d12ff51bad6e259da637f0829d02dfbb77871eeff3dacd4ed156fcaeb93d750c0c84c9234a57413359679aee'
                   '7598cb9d968fafb19e49e9db2711c811025cb45fd65e9e03cf2fbe7bdb43f27e14f97b80c86d92c957321f21da25584e7ee5b88a740dc2adf4f60d3dfe0ec8e3')
sha512sums_aarch64=('0fff2ca371c7d1eb9dd9bf1e85368b5ec61b7596819eebda51ee0ab9747a4e1f62894c05d16fc1edfb3cfce4c6ddb7f510b54af01448180dd21ecd4d3f93a017'
                    'a16c36b1d3d499f4bcaf282efc9d82b6babe465567473a496dd666019a39dbf8ec0cc910dbce76a8b019a1263d3693c86f08891aec4d91f87d34ee5064780c74')

prepare() {
  chmod +x $_appimage

  ./$_appimage --appimage-extract
}

build() {
  sed -i -E \
    "s|Exec=AppRun|Exec=env DESKTOPINTEGRATION=false /usr/bin/$pkgbase|" \
    "squashfs-root/$pkgbase.desktop"

    chmod -R a-x+rX squashfs-root/usr
}

package_caido-desktop() {
  depends=('glibc' 'gcc-libs')
  provides=('caido')

  install -Dm 755 "$srcdir/$_appimage" "$pkgdir/opt/$pkgbase/$pkgbase.AppImage"
  install -Dm 644 "$srcdir/LICENSE" "$pkgdir/opt/$pkgbase/LICENSE"

  install -Dm 644 "$srcdir/squashfs-root/$pkgbase.desktop" \
    "$pkgdir/usr/share/applications/$pkgbase.desktop"

  install -dm 755 "$pkgdir/usr/share/applications/"
  cp -a "$srcdir/squashfs-root/usr/share/icons" "$pkgdir/usr/share/"
  cp -a "$srcdir/squashfs-root/$pkgbase.desktop" \
    "$pkgdir/usr/share/applications/"

  install -dm 755 "$pkgdir/usr/bin"
  ln -s "/opt/$pkgbase/$pkgbase.AppImage" "$pkgdir/usr/bin/$pkgbase"

  install -dm 755 "$pkgdir/usr/share/licenses/$pkgname/"
  install -m 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/"
}

package_caido-cli() {
  depends=('glibc' 'gcc-libs')

  install -dm 755 "$pkgdir/usr/share/licenses/$pkgname/"
  install -m 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/"
  install -Dm 755 caido-cli "$pkgdir/usr/bin/caido-cli"
}

